<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    //document.cookie
    //setCookie();增加修改一体
    //getCookie();获取
    //removeCookie();删除

    //path   存储路径
    //domain    存储域
                ///     键   值    时间
    function setCookie(name,value,expires){
        //核心：操作字符串！;
            //字符串
        var cookie_str =name+"="+value
        //判定是否要增加过期时间、即判断时间是空还是字符串，若为字符串，则是改，若为空，则是增加
        if(typeof expires === "number"){
            var d = new Date();
            d.setDate(d.getDate()+expires)
            cookie_str += ";expires=" + d;
        }
        //把拼接好的字符串到document.cookie上；
        //查看字符串是否正确
        //consloe.log(cookie_str);
        document.cookie =cookie_str;
    }

    //获取cookie；
    function getCookie(name){
        //分割
        //一定要以分号加空格的间隔进行分割
        var cookie_arr =document.cookie.split("; ");
        for(var i = 0 ; i < cookie_arr.length;i++){
            //每条cookie =>key=value;
            var cookie_item =cookie_arr[i]
            //consloe.log(cookie_item)
            cookie_item =cookie_item.split("=");
            if(cookie_item[0]==name){
                return cookie_item[i];
            }
        }
        return "";
    }

    //删除 cookie；
    function removeCookie(name){
        setCookie(name,"",-1)
    }
</script>